<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Cache;
class Room extends Model
{

    protected $table = 'rooms';
    protected $guarded = [];

    public function member()
    {
        return $this->hasMany('App\Model\Member','room_id');
    }

    /**
     * 清除缓存
     */
    static function clear()
    {
        Cache::forget('xHotel_room_rooms');
    }

    /**
     * 生成分类数据
     * @return mixed
     */
    static function get_categories()
    {

        $room = Cache::rememberForever('xHotel_room_rooms', function () {
            return self::orderBy('sort_order')->get();
        });
        return $room;
    }

    /**
     * 检查是否有入住客户
     */
    static function is_member($id)
    {
        $room = self::with('member')->find($id);
        if ($room->member->isEmpty()) {
            return true;
        }
        return false;
    }
    
}
